package com.yc.cloud.common.websocket.core;

import com.corundumstudio.socketio.SocketIOServer;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

@Configuration
public class SocketConfig {




//    @Value("${socketio.host}:9092")
//    private String host;

    @Value("${socketio.port:9092}")
    private Integer port;

    @Bean
    public SocketIOServer socketIOServer() {
        com.corundumstudio.socketio.SocketConfig socketConfig = new com.corundumstudio.socketio.SocketConfig();
//        socketConfig.setTcpNoDelay(true);
//        socketConfig.setSoLinger(0);
        socketConfig.setReuseAddress(true);
        com.corundumstudio.socketio.Configuration config = new com.corundumstudio.socketio.Configuration();
        config.setSocketConfig(socketConfig);
        config.setRandomSession(true);
//        config.setHostname(host);
        config.setPort(port);
//        config.setBossThreads(bossCount);
//        config.setWorkerThreads(workCount);
//        config.setAllowCustomRequests(allowCustomRequests);
//        config.setUpgradeTimeout(upgradeTimeout);
//        config.setPingTimeout(pingTimeout);
//        config.setPingInterval(pingInterval);

        //设置ssl证书
//        config.setKeyStorePassword("4rs1jebt");
//        InputStream stream = SocketIOConfig.class.getResourceAsStream("/keystore.jks");
//        config.setKeyStore(stream);
        //下面屏蔽的是链接鉴权方法，由于我使用的jwt相关方法和类很多，没法往文章里写
//        config.setAuthorizationListener(new AuthorizationListener() {
//            @Override
//            public boolean isAuthorized(HandshakeData handshakeData) {
//                //获取socket链接发来的token参数
//                String token = handshakeData.getSingleUrlParam(URL_PARAM_TOKEN);
//                String display = handshakeData.getSingleUrlParam(URL_PARAM_DISPLAY);
//                //这个isPass是我的验签token方法,如果验签通过就是true,否则false,false的话就不允许建立socket链接
//                //TODO LIST
//                return true;
//            }
//        });
        return new SocketIOServer(config);

    }

}
